<?php
class editAction extends rareAction{
	public function execute(){
		$id = $this->getGetParam('id',0);
		if($id==0) forward('category/index');
		$cateDao = new DaoCategory();
		$cate = $cateDao->getOne("id='$id'");
      
        
		$this->assign('cate',$cate);
		if(Tool::_getCache('isAdmin')){
			if($cate['typeID'] == service_type::PRODUCT){
				Tool::_setCache('current','product');
			}elseif($cate['typeID'] == service_type::NEWS){
				Tool::_setCache('current','news');
			}
		}else{
			Tool::_setCache('currentID',service_menu::getCurrent('1',$type));
		}
	}
	public function executePost(){
		$id = $this->getPostParam('id',0);
		rare_go404If($id==0);
		$cate = $this->getPostParam('cate',array());
		if(empty($cate)) jsonReturn(0,'null');
		$cateDao = new DaoCategory();
		$parent = $cateDao->getOne('id='.$cate['parentID']);
		if(empty($parent)){
			$cate['path'] = "0,$id";
		}else{
			$cate['path'] = $parent['path'].",$id";
		}
		$cate['title'] = trim($cate['title']);
		$cate['description'] = trim($cate['description']);
		$cateDao->update("id='$id'",$cate);
		jsonReturn(1,'ok');
	}
}
?>
